﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] arr1 = new int[] { 1, 2, 3, 4 };
            int[] arr2 = arr1;

            arr2[0] = 0;

            foreach (int i in arr1)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("---------------------------");

            foreach (int i in arr2)
            {
                Console.WriteLine(i);
            }

            int[,] arrays = new int[,] {
            {1,2,3},
            {11,22,33},
            {111,222,333},
            {1111,2222,3333}
            };

            for (int i = 0; i < arrays.GetLength(0); i++)
            {
                for (int j = 0; j < arrays.GetLength(1); j++)
                {
                    Console.Write(arrays[i, j] + "\t");
                }

                Console.WriteLine();
            }

            Target_1();

            string name = "方灿";
            string company = "NetEase";

            Target_2(name, company);
            Target_2("方灿", "Tencent");

            int succeed = Target_3("方灿", "Perfect World");

            Console.WriteLine("succeed=" + succeed);

            int[] array = new int[] { 1, 2, 3, 4, 5 };

            Array(array);

            int Lenth = GetArrayLength(array);

            Console.WriteLine("数组Array的元素个数：" + Lenth);

            int num = 5;

            Add(ref num);

            Console.WriteLine("num：" + num);

            int a = 5;
            int b = 6;
            int max, min;
            double total, avg;

            Number(a, b, out max, out min, out total, out avg);

            Console.WriteLine("max={0} min={1} total={2} avg={3}", max, min, total, avg);

            int c = Number(100);

            Console.WriteLine("c：" + c);

            int d = AddNum(100);

            Console.WriteLine("d：" + d);

            string[] success = new string[] { "方", "灿", "一", "定", "能", "进", "游", "戏", "大", "厂" };
            string empty = "";

            for (int i = 0; i < success.Length; i++)
            {
                empty += success[i];
                if(i < success.Length - 1)
                {
                    empty += " ";
                }
            }
            Console.Write(empty);

            Console.ReadKey();

        }

        static void Target_1()
        {
            Console.WriteLine("我是方灿，我想进miHoYo");
        }

        static void Target_2(string name, string company)
        {
            Console.WriteLine("我是{0}，我想进{1}", name, company);
        }

        static int Target_3(string name, string company)
        {
            Console.WriteLine("我是{0}，我想进{1}", name, company);
            return 1;
        }

        /// <summary>
        /// 遍历一个一维数组
        /// </summary>
        static void Array(int[] array)
        {
            string arrayStr = "";

            for (int i = 0; i < array.Length; i++)
            {
                arrayStr += array[i];

                if (i < array.Length - 1)
                {
                    arrayStr += " ";
                }
            }
            Console.WriteLine(arrayStr);
        }

        /// <summary>
        /// 求数组的元素个数
        /// </summary>
        static int GetArrayLength(int[] array)
        {
            return array.Length;
        }

        /// <summary>
        /// 自增10
        /// </summary>
        static void Add(ref int num)
        {
            Console.WriteLine("num_start：" + num);

            num += 10;

            Console.WriteLine("num_end：" + num);
        }

        /// <summary>
        /// 输出两个数的最大值、最小值、和、平均值
        /// </summary>
        static void Number(int a, int b, out int max, out int min, out double total, out double avg)
        {
            //最大值、最小值
            if (a > b)
            {
                max = a;
                min = b;
            }
            else
            {
                max = b;
                min = a;
            }

            //和
            total = a + b;

            //平均值
            avg = total / 2;
        }

        /// <summary>
        /// for循环实现前n项和
        /// </summary>
        static int Number(int n)
        {
            int total = 0;
            for (int i = 0; i <= n; i++)
            {
                total += i;
            }
            return total;
        }

        /// <summary>
        /// 递归实现前n项和
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        static int AddNum(int n)
        {
            if (n == 1)
            {
                return 1;
            }
            return n + AddNum(n - 1);

        }
    }
}
